import hashlib

from django.contrib.auth.models import AbstractUser
from django.db import models
from dvadmin.system.models import Users, Dept
from ops.utils.models import table_prefix
from dvadmin.utils.models import CoreModel


class Desktop(CoreModel):
    devices_name = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备名称", help_text="设备名称")
    devices_num = models.CharField(max_length=100, blank=True, null=True, unique=True, verbose_name="设备编码", help_text="设备编码")
    devices_type = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备型号", help_text="设备型号")
    devices_usages = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备用途", help_text="设备用途")
    devices_configuration = models.CharField(max_length=100, blank=True, null=True, verbose_name="配置信息", help_text="配置信息")
    STATUS_CHOICES = (
        (0, "库存"),
        (1, "使用中"),
        (2, "损坏")
    )
    FEE_TYPE_CHOICES = (
        (0, "购买"),
        (1, "租恁"),
        (2, "其他"),
    )
    status = models.IntegerField(choices=STATUS_CHOICES, default=1, verbose_name="状态", help_text="状态")
    sort = models.IntegerField(default=1, verbose_name="显示排序", null=True, blank=True, help_text="显示排序")
    remark = models.CharField(max_length=2000, blank=True, null=True, verbose_name="备注", help_text="备注")
    devices_dept = models.ForeignKey(to=Dept, related_name='归属部门', on_delete=models.PROTECT, db_constraint=False, null=True, blank=True)
    devices_ownner = models.ForeignKey(to=Users, related_name='使用者', on_delete=models.PROTECT, db_constraint=False, null=True, blank=True)
    fee_type = models.IntegerField(choices=FEE_TYPE_CHOICES, verbose_name="费用类型", help_text="费用类型")
    fee_number = models.IntegerField(default=0, verbose_name="费用", help_text="费用")

    class Meta:
        db_table = table_prefix + 'devices_desktop'
        verbose_name = "办公设备表"
        verbose_name_plural = verbose_name
        ordering = ('create_datetime',)


class Servers(CoreModel):
    devices_name = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备名称", help_text="设备名称")
    devices_num = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备编码", help_text="设备编码")
    devices_type = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备型号", help_text="设备型号")
    devices_usages = models.CharField(max_length=100, blank=True, null=True, verbose_name="设备用途", help_text="设备用途")
    devices_cpu = models.IntegerField(blank=True, null=True, verbose_name="cpu个数", help_text="cpu个数")
    devices_mem = models.IntegerField(blank=True, null=True, verbose_name="内存", help_text="内存大小")
    devices_disk = models.IntegerField(blank=True, null=True, verbose_name="磁盘", help_text="磁盘大小")
    devices_localip = models.GenericIPAddressField(blank=True, null=True, verbose_name="内网ip", help_text="内网ip")
    devices_interip = models.GenericIPAddressField(blank=True, null=True, verbose_name="公网ip", help_text="公网ip")
    devices_dept = models.CharField(max_length=100, blank=True, null=True, verbose_name="归属部门", help_text="归属部门")
    devices_ownner = models.CharField(max_length=100, blank=True, null=True, verbose_name="使用者", help_text="使用者")
    username = models.CharField(max_length=20, blank=True, null=True, verbose_name="用户名", help_text="用户名")
    port = models.IntegerField(blank=True, null=True, verbose_name="端口", help_text="端口")
    password = models.CharField(max_length=100, blank=True, null=True, verbose_name="使用者", help_text="使用者")

    STATUS_CHOICES = (
        (0, "禁用"),
        (1, "启用"),
    )
    status = models.IntegerField(choices=STATUS_CHOICES, default=1, verbose_name="状态", help_text="状态")
    sort = models.IntegerField(default=1, verbose_name="显示排序", null=True, blank=True, help_text="显示排序")
    remark = models.CharField(max_length=2000, blank=True, null=True, verbose_name="备注", help_text="备注")

    class Meta:
        db_table = table_prefix + 'devices_servers'
        verbose_name = "服务器信息"
        verbose_name_plural = verbose_name
        ordering = ('sort',)
